package ${package.ServiceImpl};

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${superServiceImplClassPackage};
import ${package.Mapper}.${table.mapperName};
import ${package.Dto}.${dto};
import ${package.Entity}.${entity};
import ${package.queryPkg}.${query};
import ${package.Vo}.${vo};
<#if table.serviceInterface>
import ${package.Service}.${table.serviceName};
</#if>
import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.framework.db.utils.WrapperUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()<#if table.serviceInterface>, ${table.serviceName}</#if> {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}><#if table.serviceInterface> implements ${table.serviceName}</#if> {

    @Override
    public ${vo} create(${dto} data) {
        ${entity} model = INSTANCE.dtoToEntity(data);
        this.save(model);
        return INSTANCE.entityToVo(model);
    }

    @Override
    public ${vo} update(String id, ${dto} data) {
        ${entity} model = INSTANCE.dtoToEntity(data);
        model.setId(id);
        this.updateById(model);
        return INSTANCE.entityToVo(model);
    }

    @Override
    public Boolean delete(String id) {
        return this.removeById(id);
    }

    @Override
    public Boolean delete(@RequestBody ${query} query){
        LambdaQueryWrapper<${entity}> wrapper = ${table.mapperName}.createWrapper(query);
        return this.remove(wrapper);
    }

    @Override
    public ${vo} detail(String id) {
        ${entity} model = this.getById(id);
        return INSTANCE.entityToVo(model);
    }

    @Override
    public List<${vo}> findByList(${query} query) {
        LambdaQueryWrapper<${entity}> wrapper = ${table.mapperName}.createWrapper(query);
        List<${entity}> list = this.list(wrapper);
        return INSTANCE.entityToVo(list);
    }

    @Override
    public PageResultVo<${vo}> findByPage(${query} query) {
        LambdaQueryWrapper<${entity}> wrapper = ${table.mapperName}.createWrapper(query);
        Page<${entity}> page = this.page(WrapperUtils.createPage(query), wrapper);
        List<${vo}> list = INSTANCE.entityToVo(page.getRecords());
        return PageResultVo.create(page.getTotal(), list);
    }

}
</#if>
